149 lines
5.2 KiB
JavaScript
149 lines
5.2 KiB
JavaScript
const path = require('path');
|
|
const options = require('./webpack.config.options');
|
|
const StyleLintPlugin = require('stylelint-webpack-plugin');
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
|
|
const typescriptResolve = {
|
|
alias: {
|
|
'moment$': path.resolve('./node_modules/moment/min/moment-with-locales.min.js'),
|
|
'moment-timezone$': path.resolve('./node_modules/moment-timezone/builds/moment-timezone-with-data-2012-2022.min.js'),
|
|
|
|
'styles': path.resolve('./src/scss'),
|
|
},
|
|
extensions: ['.ts', '.tsx', '.js'],
|
|
};
|
|
|
|
module.exports = function (env, tsLoaderHappyPackMode) {
|
|
env = env || {};
|
|
tsLoaderHappyPackMode = (typeof tsLoaderHappyPackMode === 'undefined') ? true : tsLoaderHappyPackMode;
|
|
|
|
console.log('Webpack Environment:', env, 'tsLoaderHappyPackMode:', !!tsLoaderHappyPackMode);
|
|
|
|
const plugins = [
|
|
new StyleLintPlugin({
|
|
configFile: '.stylelintrc',
|
|
context: 'src',
|
|
emitErrors: true,
|
|
failOnError: false,
|
|
quiet: false,
|
|
}),
|
|
].concat(options.getPlugins(env));
|
|
|
|
return {
|
|
entry: {
|
|
'dist/global': [
|
|
'babel-polyfill', // this is intended to be on every single page, legacy or new!
|
|
'./src/scss/index.scss' // these are the global styles that should never be imported by a component
|
|
],
|
|
|
|
'dist/main': './src/ts/index.tsx',
|
|
},
|
|
optimization: options.getOptimizations(),
|
|
output: {
|
|
path: path.resolve(options.outputDirectory),
|
|
filename: '[name]-bundle.js',
|
|
// filename: '[name]-bundle.[chunkhash].js',
|
|
sourceMapFilename: '[file].map'
|
|
},
|
|
resolve: typescriptResolve,
|
|
devtool: 'source-map',
|
|
plugins: plugins,
|
|
module: {
|
|
rules: [
|
|
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
|
|
{
|
|
test: /\.js$/,
|
|
enforce: 'pre',
|
|
exclude: /node_modules/,
|
|
use: [
|
|
{ loader: 'source-map-loader' }
|
|
]
|
|
},
|
|
{
|
|
test: /\.tsx?$/,
|
|
enforce: 'pre',
|
|
exclude: /node_modules/,
|
|
use: [
|
|
{ loader: 'source-map-loader' },
|
|
]
|
|
},
|
|
{
|
|
test: /\.tsx?$/,
|
|
enforce: 'pre',
|
|
exclude: /node_modules/,
|
|
use: [
|
|
{
|
|
loader: 'tslint-loader',
|
|
options: {
|
|
emitErrors: !env.WARN_ON_LINT,
|
|
failOnHint: !env.WARN_ON_LINT,
|
|
typeCheck: false,
|
|
}
|
|
},
|
|
]
|
|
},
|
|
{
|
|
test: /\.jsx?$/,
|
|
exclude: /node_modules/,
|
|
use: [
|
|
{ loader: 'babel-loader' }
|
|
]
|
|
},
|
|
{
|
|
test: /\.tsx?$/,
|
|
exclude: /node_modules/,
|
|
use: [
|
|
{ loader: 'babel-loader' },
|
|
{
|
|
loader: 'ts-loader',
|
|
options: {
|
|
silent: true,
|
|
happyPackMode: tsLoaderHappyPackMode, // setting as true also implies transpileOnly: true,
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
test: /\.scss$/,
|
|
exclude: /node_modules/,
|
|
use: [
|
|
{
|
|
loader: MiniCssExtractPlugin.loader,
|
|
options: {
|
|
// you can specify a publicPath here
|
|
// by default it use publicPath in webpackOptions.output
|
|
// publicPath: '../'
|
|
}
|
|
},
|
|
{
|
|
loader: 'css-loader',
|
|
options: {
|
|
sourceMap: !!env.CSS_SOURCEMAPS
|
|
}
|
|
},
|
|
{
|
|
loader: 'sass-loader',
|
|
options: {
|
|
sourceMap: !!env.CSS_SOURCEMAPS
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
test: /\.css$/,
|
|
exclude: /node_modules/,
|
|
use: [
|
|
{ loader: 'style-loader' },
|
|
{
|
|
loader: 'css-loader',
|
|
options: {
|
|
sourceMap: !!env.CSS_SOURCEMAPS
|
|
}
|
|
}
|
|
],
|
|
}
|
|
]
|
|
}
|
|
}
|
|
};
|