mirror of
https://github.com/ritz078/transform.git
synced 2026-11-21 00:32:56 +03:00
75 lines
1.7 KiB
JavaScript
75 lines
1.7 KiB
JavaScript
const webpack = require("webpack");
|
|
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
|
|
const { ANALYZE } = process.env;
|
|
const glob = require("glob");
|
|
const LodashModuleReplacementPlugin = require("lodash-webpack-plugin");
|
|
|
|
module.exports = {
|
|
webpack: (config, { dev, isServer }) => {
|
|
config.node = {
|
|
fs: "empty"
|
|
};
|
|
|
|
config.module.rules.push({
|
|
test: /\.css$/,
|
|
use: ["style-loader", "css-loader"]
|
|
});
|
|
|
|
config.plugins.push(
|
|
new LodashModuleReplacementPlugin({
|
|
collections: true,
|
|
shorthands: true
|
|
}),
|
|
new webpack.DefinePlugin({ IN_BROWSER: !isServer })
|
|
);
|
|
|
|
config.resolve.alias = {
|
|
"babel-core": "babel-standalone"
|
|
};
|
|
|
|
// if (!dev) {
|
|
// config.plugins.push(
|
|
// new SWPrecacheWebpackPlugin({
|
|
// minify: true,
|
|
// staticFileGlobsIgnorePatterns: [/\.next\//],
|
|
// staticFileGlobs: [
|
|
// "static/**/*" // Precache all static files by default
|
|
// ],
|
|
// runtimeCaching: [
|
|
// {
|
|
// handler: "networkFirst",
|
|
// urlPattern: /^https?.*/
|
|
// }
|
|
// ]
|
|
// })
|
|
// );
|
|
// }
|
|
|
|
if (ANALYZE) {
|
|
config.plugins.push(
|
|
new BundleAnalyzerPlugin({
|
|
analyzerMode: "server",
|
|
analyzerPort: 8888,
|
|
openAnalyzer: true
|
|
})
|
|
);
|
|
}
|
|
|
|
return config;
|
|
},
|
|
|
|
exportPathMap() {
|
|
const pathMap = {};
|
|
glob
|
|
.sync("pages/**/*.js", {
|
|
ignore: ["pages/_document.js", "pages/_app.js"]
|
|
})
|
|
.forEach(s => {
|
|
const path = s.split(/(pages|\.)/)[2].replace(/^\/index$/, "/");
|
|
console.log(path);
|
|
pathMap[path] = { page: path };
|
|
});
|
|
return pathMap;
|
|
}
|
|
};
|