Created
September 26, 2016 20:24
-
-
Save YanLobat/8addd7a299b996c552b5de3a789f1bd8 to your computer and use it in GitHub Desktop.
config test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import webpack from 'webpack'; | |
import config from './webpack.config.js'; | |
import WebpackDevServer from 'webpack-dev-server'; | |
const PROD = process.env.npm_config_argv.includes('--production'); | |
config.entry.app.unshift('webpack-dev-server/client?http://localhost:9001', 'webpack/hot/only-dev-server'); | |
var compiler = webpack(config); | |
const server = new WebpackDevServer(compiler, { | |
hot: !PROD, | |
// noInfo: true, | |
}); | |
server.listen(9001); | |
if (PROD) | |
{ | |
console.info( `HMR is enabled without '--hot' flag, because it's production version.` ) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import webpack from 'webpack'; | |
import CleanWebpackPlugin from 'clean-webpack-plugin'; | |
import HtmlWebpackPlugin from 'html-webpack-plugin'; | |
import autoprefixer from 'autoprefixer'; | |
import postcssFixes from 'postcss-fixes'; | |
import path from 'path'; | |
import WriteFilePlugin from 'write-file-webpack-plugin'; | |
import ExtractTextPlugin from 'extract-text-webpack-plugin'; | |
import StyleLintPlugin from 'stylelint-webpack-plugin'; | |
const PROD = process.argv.includes('--production'); | |
module.exports = { | |
entry:{ | |
app: ['./src/components/App/index.jsx'] | |
}, | |
output: { | |
path: path.join(__dirname, './dist'), | |
filename: `common[hash].js`, | |
publicPath: './' | |
}, | |
module: { | |
preLoaders: [ | |
{ | |
test: /\.jsx?$/, | |
loader: 'eslint', exclude: /node_modules/, | |
} | |
], | |
loaders: [ | |
...PROD ? [ | |
{ | |
test: /\.scss$/, | |
exclude: /node_modules/, | |
loader: ExtractTextPlugin.extract( | |
'css-loader?modules' + | |
'&importLoaders=1' + | |
'&localIdentName=[name]__[local]___[hash:base64:5]' + | |
'!postcss-loader' + | |
'!sass-loader' | |
), | |
}, | |
] : [ | |
{ | |
test: /\.scss$/, | |
exclude: /node_modules/, | |
loaders: [ | |
'style-loader', | |
'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]', | |
'postcss-loader', | |
'sass-loader' | |
], | |
}, | |
], | |
{ | |
test: /.jsx?$/, | |
loader: 'babel-loader', | |
exclude: /node_modules/, | |
query: { | |
presets: ['es2015', 'stage-0', 'react'], | |
}, | |
}, | |
{ | |
test: /\.(png|jpg|jpeg|gif|svg)$/, | |
loader: 'url-loader', | |
query: { | |
name: '/images/[hash].[ext]', | |
limit: 10000, | |
}, | |
}, | |
], | |
}, | |
resolve: { | |
extensions: ['', '.js', '.jsx'] | |
}, | |
postcss: [ | |
autoprefixer( | |
{ | |
browsers: [ | |
'Android 2.3', | |
'Android >= 4', | |
'Chrome >= 35', | |
'Firefox >= 31', | |
'Explorer >= 9', | |
'iOS >= 7', | |
'Opera >= 12', | |
'Safari >= 7.1', | |
], | |
} | |
), | |
postcssFixes(), | |
], | |
plugins: [ | |
...PROD ? [ | |
new webpack.optimize.UglifyJsPlugin({ | |
compress: { | |
warnings: false, | |
}, | |
}), | |
new ExtractTextPlugin(`common[hash].css`), | |
new WriteFilePlugin(), | |
] : [ | |
], | |
new StyleLintPlugin({ | |
configFile: path.join(__dirname, '/stylelint.config.js'), | |
files: './src/components/**/*.scss', | |
failOnError: false, | |
}), | |
new CleanWebpackPlugin('./dist/'), | |
new HtmlWebpackPlugin({ | |
template: './src/templates/index.html', | |
}), | |
new webpack.HotModuleReplacementPlugin(), | |
new webpack.DefinePlugin({ | |
'process.env.NODE_ENV': PROD ? '"production"' : '"development"', | |
}) | |
], | |
devtool: PROD ? false: 'source-map', | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment