-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
110 lines (109 loc) · 3.89 KB
/
Copy pathwebpack.config.js
File metadata and controls
110 lines (109 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* 一个webpack配置的模板,当前为dev环境
*/
const path = require('path');
const autoprefixer = require('autoprefixer');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = (env, argv) => {
const commonConfig = {
mode: argv.mode,
entry: {
index: path.join(__dirname, './src/index.ts'),
usualComponentWeb: path.join(__dirname, './src/usualComponentWeb.ts'),
usualComponentTouch: path.join(__dirname, './src/usualComponentTouch.ts'),
},
output: {
path: path.join(__dirname, 'lib'),
filename: '[name].js',
publicPath: '/lib/',
libraryTarget: 'commonjs',
},
resolve: {
extensions: [".js", ".jsx", ".scss", ".ts", ".tsx"],
alias: {
utils: path.resolve(__dirname, './src/utils'),
static: path.resolve(__dirname, './src/static')
}
},
externals: {
'react': {
commonjs: 'react',
},
'react-dom': {
commonjs: 'react-dom',
},
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader?presets[]=react,presets[]=es2015,presets[]=stage-0'
}]
},
{
test: /\.(png|jpg|svg|gif)$/,
use: {
loader: 'url-loader',
options: {
limit: 10240, // 10K
fallback: 'file-loader',
},
},
},
{
test: /\.[s]?css$/,
use: [{
loader: 'style-loader'
}, {
loader: 'css-loader'
}, {
loader: 'sass-loader'
}, {
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
],
flexbox: 'no-2009',
remove: false,
}),
],
},
}]
}
]
},
plugins: argv.env === 'analyzer' ? [new BundleAnalyzerPlugin()] : []
};
const isDevMode = argv.mode !== 'production';
if(isDevMode){
commonConfig.externals = {};
commonConfig.entry = {
index: path.join(__dirname, './src/index.ts'),
usualComponentWeb: path.join(__dirname, './src/usualComponentWeb.ts'),
usualComponentTouch: path.join(__dirname, './src/usualComponentTouch.ts'),
indexTest: path.join(__dirname, './test/index.test.tsx'),
indexTest2: path.join(__dirname, './test/index.test2.tsx'),
indexTestTouch: path.join(__dirname, './test/index.test.touch.tsx'),
};
commonConfig.output = {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
publicPath: '/dist/',
libraryTarget: 'umd',
};
commonConfig.devServer = {
host: '127.0.0.1',
port:8088
};
}
return commonConfig;
};