2018-05-26 18:53:54 +00:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2018-06-09 12:43:18 +00:00
|
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
|
|
|
const increaseSpecificity = require('postcss-increase-specificity');
|
2018-06-09 13:47:19 +00:00
|
|
|
const JavaScriptObfuscator = require('webpack-obfuscator');
|
2019-06-15 01:57:28 +00:00
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
|
|
|
const path = require('path');
|
2018-05-26 18:53:54 +00:00
|
|
|
|
|
|
|
const devMode = process.env.NODE_ENV !== 'production';
|
|
|
|
|
2019-06-15 01:57:28 +00:00
|
|
|
const publicDir = path.join(__dirname, 'public');
|
|
|
|
const distDir = path.join(__dirname, 'dist');
|
|
|
|
|
2018-06-03 20:01:32 +00:00
|
|
|
const defaultConfig = {
|
2019-06-15 01:57:28 +00:00
|
|
|
mode: process.env.NODE_ENV || 'development',
|
|
|
|
devServer: {
|
|
|
|
contentBase: publicDir,
|
|
|
|
port: 9000
|
|
|
|
},
|
2018-05-26 18:53:54 +00:00
|
|
|
plugins: [
|
2019-06-15 01:57:28 +00:00
|
|
|
// new CleanWebpackPlugin({protectWebpackAssets: false}),
|
2018-05-26 18:53:54 +00:00
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
// Options similar to the same options in webpackOptions.output
|
|
|
|
// both options are optional
|
|
|
|
filename: devMode ? '[name].css' : '[name].[hash].css',
|
|
|
|
chunkFilename: devMode ? '[id].css' : '[id].[hash].css',
|
2018-05-29 02:49:38 +00:00
|
|
|
}),
|
2019-06-15 01:57:28 +00:00
|
|
|
new CopyPlugin([
|
|
|
|
{ from: 'public', to: '.' },
|
|
|
|
]),
|
2018-06-09 13:47:19 +00:00
|
|
|
devMode ? null : new JavaScriptObfuscator(),
|
|
|
|
].filter(i => i),
|
2018-05-26 18:53:54 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(js|jsx)$/,
|
|
|
|
exclude: /node_modules/,
|
2018-05-29 02:49:38 +00:00
|
|
|
use: ['babel-loader'],
|
2018-05-26 18:53:54 +00:00
|
|
|
},
|
|
|
|
{
|
2018-06-09 12:43:18 +00:00
|
|
|
test: /\.(scss|css)$/,
|
2018-05-26 18:53:54 +00:00
|
|
|
use: [
|
|
|
|
// fallback to style-loader in development
|
2018-06-09 13:47:19 +00:00
|
|
|
// devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
|
|
'style-loader',
|
2018-05-26 18:53:54 +00:00
|
|
|
'css-loader',
|
2018-06-09 12:43:18 +00:00
|
|
|
'cssimportant-loader',
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
ident: 'postcss',
|
|
|
|
plugins: [
|
|
|
|
increaseSpecificity({
|
|
|
|
stackableRoot: '.cleanslate',
|
|
|
|
repeat: 1,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
sourceMap: devMode,
|
|
|
|
},
|
|
|
|
},
|
2018-05-29 02:49:38 +00:00
|
|
|
'sass-loader',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2018-05-26 18:53:54 +00:00
|
|
|
},
|
|
|
|
resolve: {
|
2018-05-29 02:49:38 +00:00
|
|
|
extensions: ['*', '.js', '.jsx'],
|
2018-05-26 18:53:54 +00:00
|
|
|
},
|
2018-06-03 20:01:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = [{
|
|
|
|
...defaultConfig,
|
|
|
|
entry: './src/outputs/embeddable-widget.js',
|
2018-05-26 18:53:54 +00:00
|
|
|
output: {
|
2019-06-15 01:57:28 +00:00
|
|
|
path: distDir,
|
2018-05-26 18:53:54 +00:00
|
|
|
publicPath: '/',
|
2018-06-03 20:01:32 +00:00
|
|
|
filename: 'widget.js',
|
2018-05-29 02:49:38 +00:00
|
|
|
library: 'EmbeddableWidget',
|
|
|
|
libraryExport: 'default',
|
|
|
|
libraryTarget: 'window',
|
2018-06-03 20:01:32 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
...defaultConfig,
|
|
|
|
entry: './src/outputs/bookmarklet.js',
|
|
|
|
output: {
|
2019-06-15 01:57:28 +00:00
|
|
|
path: distDir,
|
2018-06-03 20:01:32 +00:00
|
|
|
publicPath: '/',
|
|
|
|
filename: 'bookmarklet.js',
|
|
|
|
},
|
|
|
|
}];
|