Skip to content

Commit fd9719d

Browse files
committed
updated
1 parent 3c539d6 commit fd9719d

27 files changed

+37567
-251
lines changed

.webpack/config.js

Lines changed: 0 additions & 66 deletions
This file was deleted.

.webpack/webpack.config.base.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// TODO: extract to this module all basic logic used by all configurations

.webpack/webpack.config.dev.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Used by npm dev script
2+
3+
const webpack = require('webpack');
4+
const path = require('path');
5+
const env = require('yargs').argv.env; // use --env with webpack 2
6+
//const CleanWebpackPlugin = require('clean-webpack-plugin');
7+
8+
var process = require('process');
9+
const pkg = require('../package.json');
10+
11+
let libraryName = pkg.name;
12+
13+
function _with(obj, objEditFunc) {
14+
objEditFunc(obj);
15+
return obj;
16+
}
17+
18+
/**
19+
* @type {webpack.Configuration}
20+
*/
21+
let config = {
22+
entry: {
23+
[libraryName]: path.resolve('src/index.js'),
24+
},
25+
devtool: 'source-map',
26+
mode: 'development',
27+
output: {
28+
path: path.resolve('lib/dev'),
29+
filename: "[name].js",
30+
library: libraryName,
31+
libraryTarget: 'umd',
32+
umdNamedDefine: true,
33+
globalObject: '(typeof global!=="undefined"?global:window)'
34+
},
35+
module: {
36+
rules: [{
37+
test: /(\.jsx|\.js)$/,
38+
loader: 'babel-loader',
39+
exclude: /(node_modules|bower_components)/
40+
},
41+
{
42+
test: /(\.jsx|\.js)$/,
43+
loader: 'eslint-loader',
44+
exclude: /node_modules/
45+
}
46+
]
47+
},
48+
resolve: {
49+
modules: [path.resolve('node_modules'), path.resolve('src')],
50+
extensions: ['.json', '.js', '.jsx']
51+
},
52+
//plugins: plugins,
53+
optimization: {
54+
minimize: false,
55+
splitChunks: {
56+
chunks: 'all',
57+
minChunks: 1,
58+
cacheGroups: { //to move shared code from different entries to shared chunk from here https://github.com/webpack/webpack/tree/master/examples/multiple-entry-points
59+
node_modules: {
60+
test: /node_modules/,
61+
chunks: "initial",
62+
name: "node_modules",
63+
priority: 10,
64+
enforce: true,
65+
minChunks:1,
66+
minSize:0
67+
}
68+
},
69+
},
70+
occurrenceOrder: true,
71+
namedModules: true,
72+
namedChunks: true,
73+
74+
removeAvailableModules: true,
75+
mergeDuplicateChunks: true,
76+
providedExports: true,
77+
usedExports: true,
78+
concatenateModules: true,
79+
//includeTest? {chunks:'all'}:false,
80+
},
81+
plugins: [
82+
// new webpack.optimize.CommonsChunkPlugin({
83+
// name: 'manifest'
84+
// })
85+
//new webpack.HashedModuleIdsPlugin()
86+
]
87+
};
88+
89+
90+
module.exports = config;

.webpack/webpack.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const defaultEnv = "dev"
2+
let args = require('yargs').argv;
3+
let env = args.env; // use --env with webpack 2
4+
if(!env) env = defaultEnv;
5+
6+
let res = undefined;
7+
const configFile = './webpack.config.'+env;
8+
console.log(`Loading configuration ${configFile}`)
9+
res = require(configFile);
10+
if(!res) throw new Error(`Configuration was not returned by the module ${configFile}`)
11+
module.exports = res||{};

.webpack/webpack.config.prod.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
const webpack = require('webpack');
2+
const path = require('path');
3+
const env = require('yargs').argv.env; // use --env with webpack 2
4+
//const CleanWebpackPlugin = require('clean-webpack-plugin');
5+
const UglifyPlugin = require('uglifyjs-webpack-plugin')
6+
7+
const _ = require('lodash');
8+
9+
var process = require('process');
10+
const pkg = require('../package.json');
11+
12+
let libraryName = pkg.name;
13+
14+
function _with(obj, objEditFunc) {
15+
objEditFunc(obj);
16+
return obj;
17+
}
18+
19+
/**
20+
* @param {webpack.Configuration} overrides
21+
* @returns {webpack.Configuration}
22+
*/
23+
function createConfig(overrides) {
24+
25+
/**
26+
* @type {webpack.Configuration}
27+
*/
28+
let config = {
29+
entry: {
30+
[libraryName]: path.resolve('src/index.js'),
31+
},
32+
//devtool: 'hidden-source-map',
33+
mode: 'production',
34+
output: {
35+
path: path.resolve('lib'),
36+
filename: "[name].js",
37+
library: libraryName,
38+
libraryTarget: 'umd',
39+
umdNamedDefine: true,
40+
globalObject: '(typeof global!=="undefined"?global:window)'
41+
},
42+
module: {
43+
rules: [{
44+
test: /(\.jsx|\.js)$/,
45+
loader: 'babel-loader',
46+
exclude: /(node_modules|bower_components)/
47+
},
48+
{
49+
test: /(\.jsx|\.js)$/,
50+
loader: 'eslint-loader',
51+
exclude: /node_modules/
52+
}
53+
]
54+
},
55+
resolve: {
56+
modules: [path.resolve('node_modules'), path.resolve('src')],
57+
extensions: ['.json', '.js', '.jsx']
58+
},
59+
optimization: {
60+
minimize: false,
61+
occurrenceOrder: true,
62+
namedModules: true,
63+
namedChunks: true,
64+
splitChunks:{
65+
minSize:200*1024*1024,
66+
},
67+
removeAvailableModules: true,
68+
mergeDuplicateChunks: true,
69+
providedExports: true,
70+
usedExports: true,
71+
concatenateModules: true,
72+
},
73+
plugins: [
74+
//new webpack.HashedModuleIdsPlugin()
75+
]
76+
};
77+
78+
if(overrides) config = _.merge(config, overrides);
79+
return config;
80+
}
81+
82+
83+
84+
85+
module.exports = [
86+
createConfig(),//full
87+
88+
//minimized
89+
createConfig({
90+
output:{
91+
filename:'[name].min.js'
92+
},
93+
optimization:{
94+
minimize:true,
95+
minimizer:[
96+
new UglifyPlugin({
97+
uglifyOptions:{
98+
compress:true,
99+
mangle:true,
100+
output:{
101+
comments:false,
102+
},
103+
},
104+
sourceMap:false,
105+
})
106+
]
107+
},
108+
}),
109+
];

.webpack/webpack.config.test.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//from here: https://www.threatstack.com/blog/unit-testing-with-webpack-mocha
2+
3+
const webpack = require('webpack');
4+
const path = require('path');
5+
const args = require('yargs').argv
6+
const WebpackShellPlugin = require('webpack-shell-plugin');
7+
var nodeExternals = require('webpack-node-externals');
8+
//const CleanWebpackPlugin = require('clean-webpack-plugin');
9+
10+
const env = args.env; // use --env with webpack 2
11+
const watchFlag = (args.watch||args.w);
12+
console.warn("Watch flag:", watchFlag);
13+
14+
/**
15+
* @type {webpack.Configuration}
16+
*/
17+
let config = {
18+
entry:{
19+
index:path.resolve("src/index.test.js"),
20+
},
21+
output:{
22+
path:path.resolve("lib/mocha-tests"),
23+
filename:"[name].js",
24+
library:"tests"
25+
//libraryTarget:"this",
26+
},
27+
target:"node",
28+
externals: [nodeExternals()],
29+
node:{
30+
fs:'empty'
31+
},
32+
mode:"development",
33+
devtool:"source-map",
34+
module: {
35+
rules: [{
36+
test: /(\.jsx|\.js)$/,
37+
loader: 'babel-loader',
38+
exclude: /(node_modules|bower_components)/
39+
},
40+
{
41+
test: /(\.jsx|\.js)$/,
42+
loader: 'eslint-loader',
43+
exclude: /node_modules/
44+
}
45+
]
46+
},
47+
resolve: {
48+
modules: [path.resolve('node_modules'), path.resolve('src')],
49+
extensions: ['.json', '.js', '.jsx']
50+
},
51+
optimization: {
52+
minimize:false,
53+
splitChunks:{
54+
chunks:'all',
55+
minChunks:1,
56+
cacheGroups:{
57+
node_modules: {
58+
test: /node_modules/,
59+
chunks: "all",
60+
name: "node_modules",
61+
priority: 10,
62+
enforce: true,
63+
minChunks:1,
64+
minSize:0,
65+
}
66+
},
67+
},
68+
occurrenceOrder:true,
69+
namedModules:true,
70+
namedChunks:true,
71+
72+
removeAvailableModules: true,
73+
mergeDuplicateChunks: true,
74+
providedExports: true,
75+
usedExports: true,
76+
concatenateModules: true,
77+
},
78+
plugins:[
79+
new WebpackShellPlugin({
80+
onBuildEnd: [
81+
"mocha lib/mocha-tests/index.js --colors"+(watchFlag?" --watch":""),
82+
],
83+
})
84+
]
85+
}
86+
87+
module.exports = config;

0 commit comments

Comments
 (0)