ocrcc-chatbox/webpack.config.js

98 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-05-26 18:53:54 +00:00
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const increaseSpecificity = require('postcss-increase-specificity');
const autoprefixer = require('autoprefixer');
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';
const publicDir = path.join(__dirname, 'public');
const distDir = path.join(__dirname, 'dist');
2018-06-03 20:01:32 +00:00
const defaultConfig = {
mode: process.env.NODE_ENV || 'development',
devServer: {
contentBase: publicDir,
port: 9000,
},
2018-05-26 18:53:54 +00:00
plugins: [
// 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
}),
new CopyPlugin([
{ from: 'public', to: '.' },
]),
],
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
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
emitWarning: true,
},
},
2018-05-26 18:53:54 +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',
'cssimportant-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
increaseSpecificity({
stackableRoot: '.cleanslate',
repeat: 1,
}),
autoprefixer()
],
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'],
2020-02-04 05:43:26 +00:00
},
node: { fs: 'empty' }
2018-06-03 20:01:32 +00:00
};
module.exports = [{
...defaultConfig,
2020-02-24 04:12:47 +00:00
entry: './src/outputs/embeddable-chatbox.js',
2018-05-26 18:53:54 +00:00
output: {
path: distDir,
2018-05-26 18:53:54 +00:00
publicPath: '/',
2020-02-24 04:12:47 +00:00
filename: 'chatbox.js',
library: 'EmbeddableChatbox',
2018-05-29 02:49:38 +00:00
libraryExport: 'default',
libraryTarget: 'window',
2018-06-03 20:01:32 +00:00
},
}, {
...defaultConfig,
entry: './src/outputs/bookmarklet.js',
output: {
path: distDir,
2018-06-03 20:01:32 +00:00
publicPath: '/',
filename: 'bookmarklet.js',
},
}];