mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 16:47:26 +02:00
feat: add simple webpack config
This commit is contained in:
parent
7116374adf
commit
2ab412e563
2 changed files with 65 additions and 0 deletions
55
lib/webpack/base.js
Normal file
55
lib/webpack/base.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
const Config = require('webpack-chain');
|
||||||
|
const path = require('path');
|
||||||
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
|
||||||
|
module.exports = function createBaseConfig(props) {
|
||||||
|
const {outDir, themePath, sourceDir} = props;
|
||||||
|
|
||||||
|
const config = new Config();
|
||||||
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
|
config
|
||||||
|
.mode(isProd ? 'production' : 'development')
|
||||||
|
.output.path(outDir)
|
||||||
|
.filename(isProd ? '[name].[chunkhash].js' : '[name].js')
|
||||||
|
.publicPath(isProd ? publicPath : '/');
|
||||||
|
|
||||||
|
config.resolve
|
||||||
|
.set('symlinks', true)
|
||||||
|
.alias.set('@theme', themePath)
|
||||||
|
.set('@source', sourceDir)
|
||||||
|
.set('@core', path.resolve(__dirname, '../core'))
|
||||||
|
.end();
|
||||||
|
|
||||||
|
const libDir = path.join(__dirname, '..');
|
||||||
|
config.module
|
||||||
|
.rule('js')
|
||||||
|
.test(/\.js$/)
|
||||||
|
.exclude.add(filepath => {
|
||||||
|
// Always transpile lib directory
|
||||||
|
if (filepath.startsWith(libDir)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Don't transpile node_modules
|
||||||
|
return /node_modules/.test(filepath);
|
||||||
|
})
|
||||||
|
.end()
|
||||||
|
.use('babel')
|
||||||
|
.loader('babel-loader')
|
||||||
|
.options({
|
||||||
|
// do not pick local project babel config
|
||||||
|
babelrc: false,
|
||||||
|
presets: ['env', 'react']
|
||||||
|
});
|
||||||
|
|
||||||
|
config.plugin('html-webpack-plugin').use(HtmlWebpackPlugin, [
|
||||||
|
{
|
||||||
|
inject: false,
|
||||||
|
hash: true,
|
||||||
|
template: path.resolve(__dirname, '../core/index.html'),
|
||||||
|
filename: 'index.html'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
return config;
|
||||||
|
};
|
10
lib/webpack/dev.js
Normal file
10
lib/webpack/dev.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
const path = require('path');
|
||||||
|
const createBaseConfig = require('./base');
|
||||||
|
|
||||||
|
module.exports = function createDevConfig(props) {
|
||||||
|
const config = createBaseConfig(props);
|
||||||
|
|
||||||
|
config.entry('main').add(path.resolve(__dirname, '../core/index.js'));
|
||||||
|
|
||||||
|
return config;
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue