2018-03-12 00:16:30 +08:00
|
|
|
const path = require('path');
|
|
|
|
const dev = process.env.NODE_ENV !== 'production';
|
|
|
|
|
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
2019-02-04 02:21:21 +08:00
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
2018-03-12 00:16:30 +08:00
|
|
|
|
|
|
|
const config = {
|
2018-03-17 23:20:15 +08:00
|
|
|
target: 'web',
|
2018-03-17 21:03:13 +08:00
|
|
|
mode: dev? 'development' : 'production',
|
2018-03-12 00:16:30 +08:00
|
|
|
entry: {
|
|
|
|
app: './resources/assets/js/index.js',
|
|
|
|
styles: './resources/assets/sass/styles.scss',
|
|
|
|
"export-styles": './resources/assets/sass/export-styles.scss',
|
|
|
|
"print-styles": './resources/assets/sass/print-styles.scss',
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
|
|
|
path: path.resolve(__dirname, 'public/dist')
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /(node_modules)/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
2018-07-14 17:20:49 +08:00
|
|
|
presets: [[
|
|
|
|
'@babel/preset-env', {
|
|
|
|
useBuiltIns: 'usage'
|
|
|
|
}
|
|
|
|
]]
|
2018-03-12 00:16:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
2019-02-04 02:21:21 +08:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
options: {}
|
|
|
|
},
|
|
|
|
{
|
2018-03-18 22:47:43 +08:00
|
|
|
loader: "css-loader", options: {
|
2019-02-04 02:21:21 +08:00
|
|
|
sourceMap: dev
|
|
|
|
}
|
2018-03-18 22:47:43 +08:00
|
|
|
}, {
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
ident: 'postcss',
|
|
|
|
sourceMap: dev,
|
|
|
|
plugins: (loader) => [
|
|
|
|
require('autoprefixer')(),
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
loader: "sass-loader", options: {
|
|
|
|
sourceMap: dev
|
|
|
|
}
|
2019-02-04 02:21:21 +08:00
|
|
|
}
|
|
|
|
]
|
2018-03-12 00:16:30 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2018-03-18 22:47:43 +08:00
|
|
|
plugins: [
|
2019-02-04 02:21:21 +08:00
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: "[name].css",
|
|
|
|
}),
|
2018-03-18 22:47:43 +08:00
|
|
|
]
|
2018-03-12 00:16:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (dev) {
|
|
|
|
config['devtool'] = 'inline-source-map';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dev) {
|
|
|
|
config.plugins.push(new UglifyJsPlugin());
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = config;
|