You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.0 KiB
96 lines
2.0 KiB
import webpack from 'webpack';
|
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
import ChromeExtensionReloader from 'webpack-chrome-extension-reloader';
|
|
import CopyPlugin from 'copy-webpack-plugin';
|
|
import path from 'path';
|
|
|
|
const { NODE_ENV = 'development' } = process.env;
|
|
|
|
const base = {
|
|
context: __dirname,
|
|
entry: {
|
|
background: './src/background/index.js',
|
|
'content-script': './src/content-scripts/index.js',
|
|
popup: './src/popup/popup.js'
|
|
},
|
|
output: {
|
|
path: path.join(__dirname, 'build'),
|
|
filename: '[name].js'
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
exclude: /node_modules/,
|
|
loader: 'babel-loader'
|
|
},
|
|
{
|
|
test: /\.scss$/,
|
|
use: [
|
|
{
|
|
loader: 'style-loader' // creates style nodes from JS strings
|
|
},
|
|
{
|
|
loader: 'css-loader' // translates CSS into CommonJS
|
|
},
|
|
{
|
|
loader: 'sass-loader' // compiles Sass to CSS
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
plugins: [
|
|
new CopyPlugin([
|
|
{ from: './src/manifest.json', to: './manifest.json' },
|
|
{ from: './src/assets/images', to: './images' }
|
|
]),
|
|
new HtmlWebpackPlugin({
|
|
template: './src/popup/popup.html',
|
|
chunks: ['popup']
|
|
}),
|
|
new webpack.DefinePlugin({
|
|
'process.env': {
|
|
NODE_ENV: JSON.stringify(NODE_ENV)
|
|
}
|
|
})
|
|
]
|
|
};
|
|
|
|
const development = {
|
|
...base,
|
|
mode: 'development',
|
|
devtool: '#eval-module-source-map',
|
|
module: {
|
|
...base.module
|
|
},
|
|
plugins: [
|
|
...base.plugins,
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
new ChromeExtensionReloader()
|
|
]
|
|
};
|
|
|
|
const production = {
|
|
...base,
|
|
output: {
|
|
path: path.join(__dirname, 'dist'),
|
|
filename: '[name].js'
|
|
},
|
|
mode: 'production',
|
|
devtool: '#source-map',
|
|
|
|
plugins: [
|
|
...base.plugins,
|
|
new webpack.LoaderOptionsPlugin({
|
|
minimize: true,
|
|
debug: false
|
|
})
|
|
]
|
|
};
|
|
|
|
if (NODE_ENV === 'development') {
|
|
module.exports = development;
|
|
} else {
|
|
module.exports = production;
|
|
}
|
|
|