-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwebpack.config.babel.js
More file actions
80 lines (72 loc) · 1.54 KB
/
Copy pathwebpack.config.babel.js
File metadata and controls
80 lines (72 loc) · 1.54 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
import { resolve } from 'path';
import webpack from 'webpack';
const { env } = process;
env.NODE_ENV = env.NODE_ENV || 'development';
const port = env.PORT || 3000;
const PROJECT_PATH = __dirname;
const inProject = (...args) => resolve(PROJECT_PATH, ...args);
const inSrc = inProject.bind(null, 'src');
const inTest = inProject.bind(null, 'test');
const srcDir = inSrc();
const testDir = inTest();
export default (configEnv) => {
const config = {
output: {
library: 'TinyQiniu',
libraryTarget: 'umd',
},
module: {
rules: [
{
test: /\.jsx?$/,
include: [srcDir, testDir],
loader: 'babel',
options: {
presets: [
['es2015', { modules: false }],
'stage-0',
],
plugins: [
'add-module-exports',
],
cacheDirectory: true,
babelrc: false,
},
},
],
noParse: [
inProject('node_modules', 'babel-core', 'browser.min.js')
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env.NODE_ENV),
}),
],
resolve: {
modules: [srcDir, 'node_modules'],
extensions: ['.js'],
},
devtool: 'source-map',
devServer: {
contentBase: './test',
port,
stats: {
chunkModules: false,
colors: true,
},
},
};
if (configEnv !== 'build') {
config.entry = {
test: [
'webpack-dev-server/client?http://127.0.0.1:' + port,
'./src/index.js',
],
};
config.output.filename = '[name].js';
config.output.publicPath = '/';
config.output.path = __dirname + '/test/';
}
return config;
};