File tree Expand file tree Collapse file tree 10 files changed +180
-29
lines changed Expand file tree Collapse file tree 10 files changed +180
-29
lines changed Original file line number Diff line number Diff line change 11
11
"license" : " MIT" ,
12
12
"dependencies" : {
13
13
"fetch" : " ^1.0.0" ,
14
+ "html-webpack-plugin" : " ^2.10.0" ,
14
15
"react" : " ^0.14.7"
15
16
},
16
17
"devDependencies" : {
Original file line number Diff line number Diff line change 1
- var fetch = require ( 'fetch' ) // fetch polyfill
2
- fetch ( 'https://google.com' )
1
+ // var fetch = require('fetch') // fetch polyfill
2
+ // fetch('https://google.com')
3
+ var longnamelongname = 123456 ;
4
+ console . log ( 'apistuff' ) ;
5
+ console . log ( 'apistuff' ) ;
6
+ console . log ( 'apistuff' ) ;
7
+ console . log ( 'apistuff' ) ;
8
+ console . log ( 'apistuff' ) ;
9
+ console . log ( 'apistuff' ) ;
10
+ console . log ( longnamelongname ) ;
Original file line number Diff line number Diff line change 1
- var React = require ( 'React' )
2
- React . createClass ( {
3
- // stuff
4
- } )
1
+ // var React = require('React')
2
+ // React.createClass({
3
+ // // stuff
4
+ // })
5
+ require ( './APIStuff.js' ) ;
6
+ console . log ( 'UIStuff' ) ;
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > < %= htmlWebpackPlugin.options.title || '上单'%> </ title >
6
+ </ head >
7
+ < body >
8
+
9
+ </ body >
10
+ </ html >
Original file line number Diff line number Diff line change 1
- var path = require ( 'path' )
2
- var webpack = require ( 'webpack' )
1
+ var path = require ( 'path' ) ;
3
2
4
- module . exports = {
5
- entry : [ './src/index' ] , // .js after index is optional
6
- output : {
7
- path : path . join ( __dirname , 'dist' ) ,
8
- filename : 'bundle.js'
9
- } ,
10
- plugins : [
11
- new webpack . optimize . UglifyJsPlugin ( {
12
- compressor : {
13
- warnings : false ,
14
- } ,
15
- } ) ,
16
- new webpack . optimize . OccurenceOrderPlugin ( )
17
- ] ,
18
- module : {
19
- loaders : [ {
20
- test : / \. c s s $ / ,
21
- loaders : [ 'style' , 'css' ]
22
- } ]
23
- }
24
- }
3
+ var number = 5 ;
4
+ var targetPath = path . resolve ( __dirname , 'webpackconfigs/config' + number + ".js" ) ;
5
+ module . exports = require ( targetPath ) ;
Original file line number Diff line number Diff line change
1
+ var path = require ( 'path' )
2
+ var webpack = require ( 'webpack' )
3
+
4
+ module . exports = {
5
+ entry : [ './src/index' ] , // .js after index is optional
6
+ output : {
7
+ path : path . join ( __dirname , '../dist/dist1' ) ,
8
+ filename : 'bundle.js'
9
+ } ,
10
+ module : {
11
+ loaders : [ {
12
+ test : / \. c s s $ / ,
13
+ loaders : [ 'style' , 'css' ]
14
+ } ]
15
+ }
16
+ }
17
+ /*
18
+ webpack里最小的单位是module,把所有的层级关系打包在一个文件,多个小module组成更大的module,
19
+ module有编号 __webpack_require__(7);
20
+ 每一个entry对应生成一个js文件
21
+ */
Original file line number Diff line number Diff line change
1
+ var path = require ( 'path' )
2
+ var webpack = require ( 'webpack' )
3
+
4
+ module . exports = {
5
+ entry : [ './src/index' ] , // .js after index is optional
6
+ output : {
7
+ path : path . join ( __dirname , '../dist/dist2' ) ,
8
+ filename : 'bundle.js'
9
+ } ,
10
+ module : {
11
+ loaders : [ {
12
+ test : / \. c s s $ / ,
13
+ loaders : [ 'style' , 'css' ]
14
+ } ]
15
+ } ,
16
+ plugins : [
17
+ new webpack . optimize . UglifyJsPlugin ( {
18
+ compressor : {
19
+ warnings : false ,
20
+ } ,
21
+ } )
22
+ ]
23
+ }
24
+
25
+ /*
26
+ UglifyJsPlugin 可以将冗长的变量名称精简,尽可能的压缩
27
+ */
Original file line number Diff line number Diff line change
1
+ var path = require ( 'path' )
2
+ var webpack = require ( 'webpack' )
3
+
4
+ module . exports = {
5
+ entry : [ './src/index' ] , // .js after index is optional
6
+ output : {
7
+ path : path . join ( __dirname , '../dist/dist3' ) ,
8
+ filename : 'bundle.js'
9
+ } ,
10
+ module : {
11
+ loaders : [ {
12
+ test : / \. c s s $ / ,
13
+ loaders : [ 'style' , 'css' ]
14
+ } ]
15
+ } ,
16
+ plugins : [
17
+ new webpack . optimize . OccurenceOrderPlugin ( true )
18
+ ]
19
+ }
20
+
21
+ /*
22
+ 通过module被引用的次数(出现的次数),来分配Id,用的次数多的module id就越小。
23
+ 意义不是很大。
24
+ */
Original file line number Diff line number Diff line change
1
+ var path = require ( 'path' )
2
+ var webpack = require ( 'webpack' )
3
+ var HtmlWebpackPlugin = require ( 'html-webpack-plugin' )
4
+ module . exports = {
5
+ entry : { index : [ './src/index' ] ,
6
+ UIStuff : [ './src/UIStuff' ] } , // .js after index is optional
7
+ output : {
8
+ path : path . join ( __dirname , '../dist/dist4' ) ,
9
+ filename : '[name].js'
10
+ } ,
11
+ module : {
12
+ loaders : [ {
13
+ test : / \. c s s $ / ,
14
+ loaders : [ 'style' , 'css' ]
15
+ } ]
16
+ } ,
17
+ plugins : [
18
+ new webpack . optimize . OccurenceOrderPlugin ( true ) ,
19
+ new HtmlWebpackPlugin ( {
20
+ template : './src/index.html' ,
21
+ title :'testtitle' ,
22
+ hash : true ,
23
+ chunks : [ 'common' , 'index' ] ,
24
+ inject : 'body'
25
+ } )
26
+
27
+ ]
28
+ }
29
+
30
+ /*
31
+ HtmlWebpackPlugin
32
+ hash 为生成的html引用的js添加hash值<script src="UIStuff.js?6f347301ad70b306a459">
33
+ 默认所有的chunks都会在html上引入,chunks: ['index'] 是筛选html引用的chunk
34
+ excludeChunks: ['index'] 排除不引用的chunk,
35
+ inject 控制chunk插入的地方 ,默认是body里面
36
+ */
Original file line number Diff line number Diff line change
1
+ var path = require ( 'path' )
2
+ var webpack = require ( 'webpack' )
3
+ var HtmlWebpackPlugin = require ( 'html-webpack-plugin' )
4
+ module . exports = {
5
+ entry : { index : [ './src/index' ] ,
6
+ UIStuff : [ './src/UIStuff' ] } , // .js after index is optional
7
+ output : {
8
+ path : path . join ( __dirname , '../dist/dist5' ) ,
9
+ filename : '[name].js'
10
+ } ,
11
+ module : {
12
+ loaders : [ {
13
+ test : / \. c s s $ / ,
14
+ loaders : [ 'style' , 'css' ]
15
+ } ]
16
+ } ,
17
+ plugins : [
18
+ // new webpack.optimize.OccurenceOrderPlugin(true),
19
+ new webpack . optimize . CommonsChunkPlugin ( {
20
+ name : [ "common" ] ,
21
+ filename : 'common.js' ,
22
+ minChunks : 2
23
+ } ) ,
24
+ new HtmlWebpackPlugin ( {
25
+ template : './src/index.html' ,
26
+ title :'testtitle' ,
27
+ hash : true ,
28
+ chunks : [ 'common' , 'index' ] ,
29
+ inject : 'body'
30
+ } )
31
+
32
+ ]
33
+ }
34
+
35
+ /*
36
+ HtmlWebpackPlugin
37
+ hash 为生成的html引用的js添加hash值<script src="UIStuff.js?6f347301ad70b306a459">
38
+ 默认所有的chunks都会在html上引入,chunks: ['index'] 是筛选html引用的chunk
39
+ excludeChunks: ['index'] 排除不引用的chunk,
40
+ inject 控制chunk插入的地方 ,默认是body里面
41
+ */
You can’t perform that action at this time.
0 commit comments