|
| 1 | +import webpack from 'webpack'; |
| 2 | +import path from 'path'; |
| 3 | +import autoprefixer from 'autoprefixer'; |
| 4 | +import UnminifiedWebpackPlugin from 'unminified-webpack-plugin'; |
| 5 | + |
| 6 | +const LAUNCH_COMMAND = process.env.npm_lifecycle_event; |
| 7 | +const isProduction = LAUNCH_COMMAND === 'production'; |
| 8 | +process.env.BABEL_ENV = LAUNCH_COMMAND |
| 9 | + |
| 10 | +const base = { |
| 11 | + context: __dirname + '/', |
| 12 | + entry: [ |
| 13 | + __dirname + '/app/js/app.babel.jsx' |
| 14 | + ], |
| 15 | + module: { |
| 16 | + preLoaders: [ |
| 17 | + { |
| 18 | + exclude: /src\//, |
| 19 | + loader: 'source-map' |
| 20 | + } |
| 21 | + ], |
| 22 | + loaders: [ |
| 23 | + { test: /\.(json)$/, exclude: /node_modules/, loaders: ['json-loader'] }, |
| 24 | + { test: /\.(jsx|.js|babel.jsx|babel.js)$/, |
| 25 | + exclude: /node_modules/, |
| 26 | + loader: 'babel-loader' |
| 27 | + }, |
| 28 | + { test: /\.(postcss.css)$/, loader: 'style-loader!css-loader!postcss-loader' }, |
| 29 | + { test: /\.html$/, loader: 'raw-loader' }, |
| 30 | + { |
| 31 | + test: /\.(eot|woff|ttf|svg|png|jpg|wav|mp3)$/, |
| 32 | + loader: 'url-loader?limit=30000&name=[name]-[hash].[ext]', |
| 33 | + } |
| 34 | + ] |
| 35 | + }, |
| 36 | + postcss: function () { |
| 37 | + return { |
| 38 | + defaults: [ require('precss'), require('postcss-cssnext'), require('postcss-modules') ], |
| 39 | + cleaner: [autoprefixer({ browsers: ['last 2 versions'] })] |
| 40 | + }; |
| 41 | + }, |
| 42 | + output: { |
| 43 | + path: __dirname + '/app/build/', |
| 44 | + filename: 'mojs-curve-editor.min.js', |
| 45 | + publicPath: 'build/', |
| 46 | + library: 'mojs-curve-editor', |
| 47 | + libraryTarget: 'umd', |
| 48 | + umdNamedDefine: true, |
| 49 | + }, |
| 50 | + plugins: [new UnminifiedWebpackPlugin()], |
| 51 | + resolve: { |
| 52 | + root: [ path.resolve('./') ], |
| 53 | + moduleDirectories: ['node_modules'], |
| 54 | + target: 'node', |
| 55 | + extensions: [ |
| 56 | + '', '.js', '.babel.js', '.babel.jsx', |
| 57 | + '.postcss.css', '.css', '.json' |
| 58 | + ] |
| 59 | + } |
| 60 | +}; |
| 61 | + |
| 62 | +const productionPlugin = new webpack.DefinePlugin({ |
| 63 | + 'process.env': { |
| 64 | + NODE_ENV: JSON.stringify('production') |
| 65 | + } |
| 66 | +}) |
| 67 | + |
| 68 | +const developmentConfig = { |
| 69 | + // devtool: 'inline-source-map' |
| 70 | + // watch: true, |
| 71 | +} |
| 72 | + |
| 73 | +const productionConfig = { |
| 74 | + // devtool: 'source-map', |
| 75 | + plugins: [productionPlugin, new webpack.optimize.UglifyJsPlugin({compress: {warnings: false}})] |
| 76 | +} |
| 77 | + |
| 78 | +export default Object.assign({}, base, isProduction === true ? productionConfig : developmentConfig) |
0 commit comments