Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const TerserPlugin = require('terser-webpack-plugin');
- const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
- const env = process.env.NODE_ENV;
- const publicPath = process.env.PUBLIC_PATH ? `${process.env.PUBLIC_PATH}/` : process.env.PUBLIC_PATH;
- if (!['development', 'production'].includes(env)) {
- throw new Error('Invalid NODE_ENV');
- }
- if (!process.env.LIB_NAME) {
- throw new Error('Invalid LIB_NAME');
- }
- module.exports = {
- mode: env,
- devtool: 'source-map',
- entry: path.resolve(__dirname, `./src/${process.env.LIB_NAME}/index.js`),
- module: {
- rules: [
- {
- test: /\.js$/i,
- loader: 'babel-loader',
- exclude: [/node_modules/],
- options: {
- presets: [
- [
- '@babel/preset-env',
- {
- useBuiltIns: 'usage',
- },
- ],
- ],
- },
- },
- {
- test: /\.css$/i,
- use: ['style-loader', 'css-loader?sourceMap'],
- },
- {
- test: /\.(svg|png|jpe?g|gif)$/i,
- use: [
- {
- loader: 'file-loader',
- options: {},
- },
- ],
- },
- {
- test: /\.(ttf|eot|woff|woff2)$/i,
- use: {
- loader: 'file-loader',
- options: {
- name: 'fonts/[name].[ext]',
- },
- },
- },
- {
- test: /\.html$/,
- exclude: /node_modules/,
- use: [
- {
- loader: 'html-loader',
- options: {
- ignoreCustomFragments: [/\{\{.*?}}/],
- root: path.resolve(__dirname, 'src'),
- attrs: ['img:src', 'link:href'],
- },
- },
- ],
- },
- ],
- },
- output: {
- chunkFilename: '[id].[contenthash:8].js',
- path: path.resolve(__dirname, `./dist-${process.env.LIB_NAME}`),
- publicPath,
- library: 'MobileStories',
- },
- plugins: [
- new HtmlWebpackPlugin({
- minify: {
- removeComments: true,
- sortAttributes: true,
- keepClosingSlash: true,
- collapseWhitespace: true,
- },
- filename: 'index.html',
- template: path.resolve(__dirname, `./src/${process.env.LIB_NAME}/index.html`),
- }),
- ],
- optimization: {
- minimizer: [new TerserPlugin(), new OptimizeCSSAssetsPlugin({})],
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement