Files
transform/next.config.js
T
2018-04-26 18:21:02 +05:30

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;
}
};