Webpack issues with MGT version 4
Ofer-Gal opened this issue · 3 comments
Ofer-Gal commented
I assume you mean \node_modules\spfx-fast-serve-helpers\lib\templates\webpack.extend.js
/*
* User webpack settings file. You can add your own settings here.
* Changes from this file will be merged into the base webpack configuration file.
* This file will not be overwritten by the subsequent spfx-fast-serve calls.
*/
/**
* you can add your project related webpack configuration here, it will be merged using webpack-merge module
* i.e. plugins: [new webpack.Plugin()]
*/
const webpackConfig = {
}
/**
* For even more fine-grained control, you can apply custom webpack settings using below function
* @param {object} initialWebpackConfig - initial webpack config object
* @param {object} webpack - webpack object, used by SPFx pipeline
* @returns webpack config object
*/
const transformConfig = function (initialWebpackConfig, webpack) {
// transform the initial webpack config here, i.e.
// initialWebpackConfig.plugins.push(new webpack.Plugin()); etc.
return initialWebpackConfig;
}
module.exports = {
webpackConfig,
transformConfig
}
thank you
Ofer-Gal commented
I am guilty of not reading "Webpack extensibility" but even trying to use the example in samples/advanced/fast-serve/webpack.extend.js it did not work.
I don't understand webpack that much.
s-KaiNet commented
Just try to put below code in your webpack.extend.js:
/*
* User webpack settings file. You can add your own settings here.
* Changes from this file will be merged into the base webpack configuration file.
* This file will not be overwritten by the subsequent spfx-fast-serve calls.
*/
// you can add your project related webpack configuration here, it will be merged using webpack-merge module
// i.e. plugins: [new webpack.Plugin()]
const webpackConfig = {
module: {
rules: [{
test: /\.js$/,
include: [
/lit/,
/@lit/,
/lit-html/
],
use: {
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-transform-optional-chaining',
'@babel/plugin-transform-nullish-coalescing-operator',
'@babel/plugin-transform-logical-assignment-operators'
]
}
}
}]
}
}
// for even more fine-grained control, you can apply custom webpack settings using below function
const transformConfig = function (initialWebpackConfig, webpack) {
// transform the initial webpack config here, i.e.
// initialWebpackConfig.plugins.push(new webpack.Plugin()); etc.
return initialWebpackConfig;
}
module.exports = {
webpackConfig,
transformConfig
}
Ofer-Gal commented
That worked fine.
Thanks!