-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
90 lines (79 loc) · 2.63 KB
/
webpack.config.js
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
'use strict';
var webpack = require('webpack');
var path = require('path');
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js');
//var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js');
/*1.Webpack_10*/
// module.exports = {
// entry: './Webpack_10/app.jsx',
// output: {
// path: './Webpack_10/',
// filename: 'app.js'
// },
// module:{
// loaders: [
// {
// test: /\.jsx$/,
// loader: 'jsx-loader'
// }
// ]
// }
// }
/*2.Todolist_11*/
module.exports = {
entry: [
"./Todolist_11/src/entry.js"
],
output: {
path: './Todolist_11/dist/',
filename: "app.js"
},
externals: { //使用自己带的库(需要在html中加载),遇到require的时候不用,只用全局变量
'react': 'React',
'react-dom': 'ReactDOM'
},
resolve: { //require的时候可以省略后缀
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
// Skip any files outside of your project's `src` directory
// include: [
// path.resolve(__dirname, "/Todolist_11/src"),
// ],
exclude: [
path.resolve(__dirname, "node_modules"),
],
test: /\.js$/,
loader: 'babel-loader',
query: {
plugins: ['transform-runtime'],
presets:['es2015','react'] //因为这个没装,浪费了我两天时间
//npm install babel babel-core --save-dev
//npm install babel-loader babel-preset-es2015 --save-dev
//npm install babel-preset-react --save-dev
//If you want to use experimental ES7 features
//npm install babel-preset-stage-0 --save-dev
//npm install babel-polyfill --save
//npm install babel-runtime --save
//npm install babel-plugin-transform-runtime --save-dev
}
},{
// include: [
// path.resolve(__dirname, "/Todolist_11/src"),
// ],
exclude: [
path.resolve(__dirname, "node_modules"),
],
test: /\.jsx$/,
loader: 'babel-loader',
query: {
plugins: ['transform-runtime'],
presets:['es2015','react']
}
}
]
},
plugins: [commonsPlugin] //打包多个入口文件时会提取出公用的部分,生成common.js
};