11'use strict'
22
3+ // Silence webpack2 deprecation warnings
4+ // https://github.com/vuejs/vue-loader/issues/666
5+ process . noDeprecation = true
6+
37const path = require ( 'path' )
48const HtmlWebpackPlugin = require ( 'html-webpack-plugin' )
59const webpack = require ( 'webpack' )
610
11+ // Paths to be used for webpack configuration
12+ const paths = {
13+ appSrc : path . join ( process . cwd ( ) , 'src' ) ,
14+ appIndex : path . join ( process . cwd ( ) , 'src' , 'index.js' ) ,
15+ appBuild : path . join ( process . cwd ( ) , 'build' ) ,
16+ public : '/'
17+ }
18+
719module . exports = {
820 entry : {
921 main : [
10- path . join ( process . cwd ( ) , 'src' , 'index.js' )
22+ // Your app's code
23+ paths . appIndex
1124 ]
1225 } ,
1326 output : {
27+ // This is the productin JS bundle containing code from all our entry points.
1428 filename : 'bundle.js' ,
15- path : path . join ( process . cwd ( ) , 'build' )
29+ // The output path where webpack will write the bundle
30+ path : paths . appBuild
1631 } ,
1732 module : {
1833 rules : [
1934 {
35+ // We use babel-loader to transipile every .js or .jsx file
2036 test : / \. j s x ? $ / ,
2137 loader : 'babel-loader' ,
38+ // Including over excluding as a whitelist is easier to maintain than a blacklist.
39+ // as per http://stackoverflow.com/questions/31675025/how-to-exclude-nested-node-module-folders-from-a-loader-in-webpack
40+ include : paths . appSrc ,
2241 options : {
42+ // This is a feature of `babel-loader` for webpack (not Babel itself).
43+ // It enables caching results in ./node_modules/.cache/babel-loader/
44+ // directory for faster rebuilds.
2345 cacheDirectory : true ,
46+ // Instead of relying on a babelrc file to configure babel (or in package.json configs)
47+ // We speficy here which presets to use. In the future this could be moved to it's own
48+ // package as create-react-app does with their 'babel-preset-react-app module.
49+ // As uglify doesn't support es6 code yet, the uglify param will tell babel plugin to transpile to es5
50+ // in order for the output to be uglified.
2451 presets : [
2552 [ 'env' , {
2653 'targets' : {
@@ -30,75 +57,36 @@ module.exports = {
3057 } ]
3158 ] ,
3259 plugins : [
33- [ 'transform-react-jsx' , { pragma : 'Snabbdom.createElement' } ]
60+ // https://cycle.js.org/getting-started.html#getting-started-coding-consider-jsx
61+ // This allow us to use JSX to create virtual dom elements instead of Snabbdom helpers like div(), input(), ..
62+ [ 'transform-react-jsx' , { pragma : 'Snabbdom.createElement' } ] ,
63+ // Allow Babel to transform rest properties for object destructuring assignment and spread properties for object literals.
64+ [ 'transform-object-rest-spread' ]
3465 ]
35- } ,
36- exclude : / n o d e _ m o d u l e s /
66+ }
3767 }
3868 ]
3969 } ,
4070 plugins : [
41- new webpack . HotModuleReplacementPlugin ( ) ,
71+ // Generates an `index.html` file with the <script> injected.
4272 new HtmlWebpackPlugin ( {
4373 template : 'public/index.html' ,
4474 inject : true ,
4575 favicon : 'public/favicon.png' ,
4676 hash : true
4777 } ) ,
78+ // Makes environment variables available to the JS code, fallback to 'production'
79+ new webpack . DefinePlugin ( {
80+ PRODUCTION : JSON . stringify ( process . env . NODE_ENV === 'production' )
81+ } ) ,
82+ // To be used for JSX support
4883 new webpack . ProvidePlugin ( {
4984 Snabbdom : 'snabbdom-pragma'
5085 } ) ,
51- new webpack . optimize . UglifyJsPlugin ( ) ,
52- new webpack . LoaderOptionsPlugin ( {
53- minimize : true ,
54- debug : false
86+ // Uglify plugin, depending on the devtool options, Source Maps are generated.
87+ new webpack . optimize . UglifyJsPlugin ( {
88+ sourceMap : this . devtool && this . devtool . indexOf ( 'source-map' ) >= 0
5589 } )
56- ]
90+ ] ,
91+ devtool : 'cheap-module-source-map'
5792}
58-
59- // 'use strict'
60-
61- // const fs = require('fs-extra')
62- // const path = require('path')
63- // const mkdirp = require('mkdirp')
64- // const webpack = require('webpack')
65- // const ProgressBarPlugin = require('progress-bar-webpack-plugin')
66-
67- // const buildPath = path.join(process.cwd(), 'build')
68- // const publicPath = path.join(process.cwd(), 'public')
69-
70- // mkdirp.sync(buildPath)
71-
72- // const compiler = webpack({
73- // entry: [
74- // './src/'
75- // ],
76- // output: {
77- // filename: 'bundle.js',
78- // path: './public/'
79- // },
80- // module: {
81- // loaders: [
82- // {
83- // test: /\.js$/,
84- // loader: 'babel',
85- // query: {
86- // presets: ['es2015']
87- // },
88- // exclude: /node_modules/
89- // }
90- // ]
91- // },
92- // plugins: [
93- // new ProgressBarPlugin(),
94- // new webpack.optimize.UglifyJsPlugin({minimize: true})
95- // ]
96- // })
97-
98- // compiler.run((err, stats) => {
99- // if (err) {
100- // console.log(err)
101- // } else {
102- // fs.copySync(publicPath, buildPath)
103- // }
104- // })
0 commit comments