Skip to content

Commit 333bc3b

Browse files
committed
feat: fix chunk name
1 parent ce4c93c commit 333bc3b

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pri",
3-
"version": "0.2.14",
3+
"version": "0.2.15",
44
"types": "src/index.ts",
55
"main": "built/index.js",
66
"scripts": {

src/utils/create-entry.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export async function createEntry(info: IProjectInfo, projectRootPath: string, e
177177
const filePath = path.parse(route.filePath)
178178
const relativePageFilePath = path.relative(projectRootPath, filePath.dir + "/" + filePath.name)
179179
const componentName = safeName(relativePageFilePath) + md5(relativePageFilePath).slice(0, 5)
180-
const chunkName = relativePageFilePath.split("/").slice(2).join("-")
180+
const chunkName = _.camelCase(route.path) || "index"
181181

182182
const pathInfo = path.parse(route.filePath)
183183

@@ -199,7 +199,7 @@ export async function createEntry(info: IProjectInfo, projectRootPath: string, e
199199
} else {
200200
const importCode = info.stores.length === 0 ?
201201
`import(/* webpackChunkName: "${chunkName}" */ "${path.join(pathInfo.dir, pathInfo.name)}")` :
202-
`import(/* webpackChunkName: "${chunkName}" */"${path.join(pathInfo.dir, pathInfo.name)}").then(res => Connect()(res.default)) `
202+
`import(/* webpackChunkName: "${chunkName}" */ "${path.join(pathInfo.dir, pathInfo.name)}").then(res => Connect()(res.default)) `
203203

204204
entryText.pageImporter += `
205205
const ${componentName} = Loadable({
@@ -278,7 +278,7 @@ export async function createEntry(info: IProjectInfo, projectRootPath: string, e
278278
const wrapperStr = `<${MARKDOWN_WRAPPER}>{code.default}</${MARKDOWN_WRAPPER}>`
279279
if (info.hasMarkdownFile) {
280280
importCode = `
281-
import(/* webpackChunkName: "${chunkName}" */ "${markdownTsAbsolutePathWithoutExt}").then(code => {
281+
import(/* webpackChunkName: "${chunkName}" */ " ${markdownTsAbsolutePathWithoutExt}").then(code => {
282282
return () => (
283283
<${MARKDOWN_LAYOUT_NAME}>
284284
${wrapperStr}
@@ -288,7 +288,7 @@ export async function createEntry(info: IProjectInfo, projectRootPath: string, e
288288
`
289289
} else {
290290
importCode = `
291-
import(/* webpackChunkName: "${chunkName}" */ "${markdownTsAbsolutePathWithoutExt}").then(code => {
291+
import(/* webpackChunkName: "${chunkName}" */ " ${markdownTsAbsolutePathWithoutExt}").then(code => {
292292
return () => (${wrapperStr})
293293
})
294294
`

src/utils/webpack-config.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const config: webpack.Configuration = {
4343
path: distDir,
4444
filename: distFileName + ".js",
4545
publicPath,
46-
chunkFilename: "[name].chunk.js",
46+
chunkFilename: "[id].chunk.js",
4747
},
4848

4949
module: {
@@ -83,11 +83,27 @@ const config: webpack.Configuration = {
8383
},
8484
{
8585
test: /\.scss$/,
86-
use: ["style-loader", "css-loader", "sass-loader"],
86+
use: env === "local" ?
87+
["style-loader", "css-loader", "sass-loader"] :
88+
ExtractTextPlugin.extract({
89+
fallback: "style-loader",
90+
use: [{
91+
loader: "css-loader",
92+
options: { minimize: true }
93+
}, "sass-loader"]
94+
})
8795
},
8896
{
8997
test: /\.less$/,
90-
use: ["style-loader", "css-loader", "less-loader"],
98+
use: env === "local" ?
99+
["style-loader", "css-loader", "less-loader"] :
100+
ExtractTextPlugin.extract({
101+
fallback: "style-loader",
102+
use: [{
103+
loader: "css-loader",
104+
options: { minimize: true }
105+
}, "less-loader"]
106+
})
91107
}
92108
]
93109
},

0 commit comments

Comments
 (0)