mirror of
https://github.com/Safe-Support-Chat/ocrcc-chatbox
synced 2024-11-25 04:04:53 +00:00
123 lines
2.9 KiB
JavaScript
123 lines
2.9 KiB
JavaScript
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');
|
|
|
|
const devMode = process.env.NODE_ENV !== 'production';
|
|
|
|
const publicDir = path.join(__dirname, 'public');
|
|
const distDir = path.join(__dirname, 'dist');
|
|
|
|
const defaultConfig = {
|
|
mode: process.env.NODE_ENV || 'development',
|
|
devServer: {
|
|
contentBase: publicDir,
|
|
port: 9000,
|
|
},
|
|
plugins: [
|
|
// new CleanWebpackPlugin({protectWebpackAssets: false}),
|
|
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',
|
|
}),
|
|
new CopyPlugin([
|
|
{ from: 'public', to: '.' },
|
|
]),
|
|
],
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.(js|jsx)$/,
|
|
exclude: /node_modules/,
|
|
use: ['babel-loader'],
|
|
},
|
|
{
|
|
test: /\.js$/,
|
|
exclude: /node_modules/,
|
|
loader: 'eslint-loader',
|
|
options: {
|
|
emitWarning: true,
|
|
},
|
|
},
|
|
{
|
|
test: /\.(scss|css)$/,
|
|
use: [
|
|
// fallback to style-loader in development
|
|
// devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
'style-loader',
|
|
'css-loader',
|
|
'cssimportant-loader',
|
|
{
|
|
loader: 'postcss-loader',
|
|
options: {
|
|
ident: 'postcss',
|
|
plugins: [
|
|
increaseSpecificity({
|
|
stackableRoot: '.cleanslate',
|
|
repeat: 1,
|
|
}),
|
|
autoprefixer()
|
|
],
|
|
sourceMap: devMode,
|
|
},
|
|
},
|
|
'sass-loader',
|
|
],
|
|
},
|
|
],
|
|
},
|
|
resolve: {
|
|
extensions: ['*', '.js', '.jsx'],
|
|
},
|
|
node: { fs: 'empty' }
|
|
};
|
|
|
|
module.exports = [{
|
|
...defaultConfig,
|
|
entry: './src/outputs/embeddable-chatbox.js',
|
|
output: {
|
|
path: distDir,
|
|
publicPath: '/',
|
|
filename: 'chatbox.js',
|
|
library: 'EmbeddableChatbox',
|
|
libraryExport: 'default',
|
|
libraryTarget: 'window',
|
|
},
|
|
}, {
|
|
...defaultConfig,
|
|
entry: './src/outputs/bookmarklet.js',
|
|
output: {
|
|
path: distDir,
|
|
publicPath: '/',
|
|
filename: 'bookmarklet.js',
|
|
},
|
|
}, {
|
|
...defaultConfig,
|
|
entry: './src/outputs/component.js',
|
|
output: {
|
|
path: distDir,
|
|
publicPath: '/',
|
|
filename: 'component.js',
|
|
library: 'Chatbox',
|
|
libraryExport: 'default',
|
|
libraryTarget: 'commonjs2',
|
|
},
|
|
externals: {
|
|
react: {
|
|
commonjs: "react",
|
|
commonjs2: "react",
|
|
amd: "React",
|
|
root: "React"
|
|
},
|
|
"react-dom": {
|
|
commonjs: "react-dom",
|
|
commonjs2: "react-dom",
|
|
amd: "ReactDOM",
|
|
root: "ReactDOM"
|
|
}
|
|
}
|
|
}];
|