Skip to content

Commit

Permalink
Merge pull request #1202 from alibaba/fix-document-public
Browse files Browse the repository at this point in the history
fix: fix document plugin public
  • Loading branch information
Orange-C authored Aug 6, 2019
2 parents 510b9d9 + 168b106 commit ec07f30
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/rax-plugin-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rax-plugin-app",
"version": "0.1.0-2",
"version": "0.1.0-3",
"description": "rax app base plugins",
"license": "BSD-3-Clause",
"main": "src/index.js",
Expand Down
4 changes: 1 addition & 3 deletions packages/rax-plugin-app/src/config/web/getBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const getWebpackBase = require('../getWebpackBase');

module.exports = (context) => {
const { rootDir, userConfig } = context;
const { publicPath } = userConfig;
const { rootDir } = context;

const config = getWebpackBase(context);

Expand Down Expand Up @@ -85,7 +84,6 @@ module.exports = (context) => {
config.plugin('document')
.use(UniversalDocumentPlugin, [{
rootDir,
publicPath,
path: 'src/document/index.jsx',
render: serverRender.renderToString,
}]);
Expand Down
2 changes: 1 addition & 1 deletion packages/rax-plugin-app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const defaultUserConfig = require('./config/defaultUserConfig');

module.exports = ({ chainWebpack, registerConfig, context, onHook }, options = {}) => {
// set default config
context.userConfig = deepmerge(context.userConfig, defaultUserConfig);
context.userConfig = deepmerge(defaultUserConfig, context.userConfig);

const { targets = [] } = options;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ module.exports = class UniversalDocumentPlugin {
}

this.rootDir = options.rootDir ? options.rootDir : process.cwd();
this.publicPath = options.publicPath ? options.publicPath : '/';
this.documentPath = options.path ? options.path : 'src/document/index.jsx';
}

apply(compiler) {
compiler.hooks.emit.tapAsync('UniversalDocumentPlugin', (compilation, callback) => {
const { publicPath } = compilation.outputOptions;

const filename = path.resolve(this.rootDir, this.documentPath);
if (!existsSync(filename)) throw new Error(`File ${filename} is not exists, please check.`);

Expand All @@ -37,7 +38,7 @@ module.exports = class UniversalDocumentPlugin {

// get document html string
const source = this.render(require('rax').createElement(documentElement, {
publicPath: this.publicPath,
publicPath,
styles: [],
scripts: ['web/index.js'],
}));
Expand Down

0 comments on commit ec07f30

Please # to comment.